package expressions;

import values.Value;
import base.Environment;
import base.Identifier;

public class VariableAccess implements Expression {

	private Identifier identifier;

	/**
	 * Creates an expression that represents an access to the variable
	 * identified by 'identifier'
	 * 
	 * @param identifier
	 *            the variable's identifier
	 */

	public VariableAccess(Identifier identifier) {

		this.identifier = identifier;
	}

	/**
	 * Returns the value of the variable referred by 'identifier'. 'identifier'
	 * has to be part of the environment env.
	 */

	public Value eval(Environment env) {
		assert env.contains(this.identifier);

		return env.getValue(this.identifier);
	}

	public Identifier getIdentifier() {
		return this.identifier;
	}
}
